title: SaferPluginHelpers
icon: shapesTable des matières
La classe SaferPluginHelpers fournit diverses méthodes d'aide pour le plugin Safer.
import(string $path, bool $import_again = false, bool $no_cache = false): mixedpublic static function import(string $path, bool $import_again = false, bool $no_cache = false): mixed
Importe un fichier PHP et retourne le résultat.
true, le fichier sera importé à nouveau même s'il a déjà été importé (par défaut : false).true, le fichier ne sera pas mis en cache (par défaut : false).$result = SaferPluginHelpers::import('/path/to/file.php');
relativeDifference(float $a, float $b): stringpublic static function relativeDifference(float $a, float $b): string
Calcule la différence relative entre deux nombres flottants.
$difference = SaferPluginHelpers::relativeDifference(120, 100); // '20.0'
exec(string $command, bool $async)public static function exec(string $command, bool $async)
Exécute une commande soit de manière synchrone, soit de manière asynchrone.
true, la commande est exécutée de manière asynchrone ; sinon, elle est exécutée de manière synchrone.SaferPluginHelpers::exec('php script.php', true); // Exécution asynchrone
SaferPluginHelpers::exec('php script.php', false); // Exécution synchrone
endRequest(mixed $content)public static function endRequest(mixed $content)
Termine la requête en cours et envoie le contenu spécifié.
SaferPluginHelpers::endRequest('Hello, world!');
SaferPluginHelpers::endRequest(function() { echo 'Goodbye, world!'; });
SaferPluginHelpers::endRequest(['First part', function() { echo 'Second part'; }]);
gettype(mixed $e): stringpublic static function gettype(mixed $e): string
Obtient le type d'une valeur.
$type = SaferPluginHelpers::gettype(123); // 'numeric'
$type = SaferPluginHelpers::gettype('test'); // 'string'
is_stringable(mixed $e): boolpublic static function is_stringable(mixed $e): bool
Vérifie si une valeur peut être convertie en chaîne de caractères.
true si la valeur peut être convertie en chaîne, false sinon.$isStringable = SaferPluginHelpers::is_stringable(123); // true
$isStringable = SaferPluginHelpers::is_stringable(new stdClass()); // false
bind(callable $callback, ...$args): callablepublic static function bind(callable $callback, ...$args): callable
Lie une fonction callable avec des arguments.
$boundFunction = SaferPluginHelpers::bind('strlen', 'test');
echo $boundFunction(); // 4
import utilise un cache pour éviter les imports répétés, à moins que no_cache soit true.endRequest termine la requête HTTP en cours et envoie le contenu spécifié tout en fermant proprement la connexion.gettype et is_stringable aident à déterminer le type et la stringabilité des valeurs respectivement.